package cn.community.care.module.system.controller.admin.info;

import cn.community.care.module.system.controller.admin.info.vo.InfoPageReqVO;
import cn.community.care.module.system.controller.admin.info.vo.InfoRespVO;
import cn.community.care.module.system.controller.admin.info.vo.InfoSaveReqVO;
import cn.community.care.module.system.dal.dataobject.info.InfoDO;
import cn.community.care.module.system.service.info.InfoService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.community.care.framework.common.pojo.PageParam;
import cn.community.care.framework.common.pojo.PageResult;
import cn.community.care.framework.common.pojo.CommonResult;
import cn.community.care.framework.common.util.object.BeanUtils;
import static cn.community.care.framework.common.pojo.CommonResult.success;

import cn.community.care.framework.excel.core.util.ExcelUtils;

import cn.community.care.framework.operatelog.core.annotations.OperateLog;
import static cn.community.care.framework.operatelog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 房间信息")
@RestController
@RequestMapping("/room/info")
@Validated
public class InfoController {

    @Resource
    private InfoService infoService;

    @PostMapping("/create")
    @Operation(summary = "创建房间信息")
    public CommonResult<Long> createInfo(@Valid @RequestBody InfoSaveReqVO createReqVO) {
        return success(infoService.createInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新房间信息")
    public CommonResult<Boolean> updateInfo(@Valid @RequestBody InfoSaveReqVO updateReqVO) {
        infoService.updateInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除房间信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteInfo(@RequestParam("id") Long id) {
        infoService.deleteInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得房间信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<InfoRespVO> getInfo(@RequestParam("id") Long id) {
        InfoDO info = infoService.getInfo(id);
        return success(BeanUtils.toBean(info, InfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得房间信息分页")
    public CommonResult<PageResult<InfoRespVO>> getInfoPage(@Valid InfoPageReqVO pageReqVO) {
        PageResult<InfoRespVO> pageResult = infoService.getInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, InfoRespVO.class));
    }

    @GetMapping("/all")
    @Operation(summary = "获得房间信息分页")
    public CommonResult<PageResult<InfoRespVO>> all(@Valid InfoPageReqVO pageReqVO) {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        PageResult<InfoRespVO> pageResult = infoService.getInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, InfoRespVO.class));
    }

}